#将xgboost算法应用于多分类问题
import xgboost as xgb
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# 加载数据集
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42)

# 设置模型参数
params = {
    'objective': 'multi:softmax',  # 多分类问题
    'num_class': 3,  # 类别数
    'max_depth': 4,  # 树的最大深度
    'eta': 0.3,  # 学习率
    'eval_metric': 'mlogloss'  # 评估指标
}

# 训练模型
dtrain = xgb.DMatrix(X_train, label=y_train)
model = xgb.train(params, dtrain, num_boost_round=10)
model_structure = model.get_dump(dump_format='text')

# 打印模型结构信息
for tree in model_structure:
    print(tree)
from sklearn.decomposition import KernelPCA